package com.kof.picviewer;

import io.undertow.Undertow;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.server.handlers.resource.ResourceHandler;

import java.nio.file.Paths;

public class StaticHtmlServer {

    public static String HTTP_SERVER_URL;

    /**
     * 运行本地http服务器
     */
    public static void runHttpServer() {
        int port = 8080;
        // 指定静态文件目录
        String staticFilesDir = "web/dist";
        Undertow server = Undertow.builder()
                .addHttpListener(port, "0.0.0.0")
                .setHandler(new ResourceHandler(new FileResourceManager(Paths.get(staticFilesDir).toFile())))
                .build();

        server.start();
        HTTP_SERVER_URL = "http://localhost:" + port;
        System.out.println("Server started on port " + port);
    }
}
